package com.company.multidimensiontest;

import android.opengl.GLU;
import android.opengl.GLSurfaceView.Renderer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class ClearRenderer implements Renderer {
    
    private float mRed, mGreen, mBlue;
    private float angle = 45;
    private Square mSquare = new Square();
    
    public void setColor(float r, float g, float b){
        mRed = r;
        mGreen = g;
        mBlue = b;
    }

    @Override
    public void onDrawFrame(GL10 gl) {
        gl.glClearColor(mRed, mGreen, mBlue, 1.0f);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        gl.glLoadIdentity();
        gl.glTranslatef(0, 0, -10);
        
        gl.glPushMatrix();
        gl.glRotatef(angle, 1, .5f, 0);        
        mSquare.draw(gl);
        gl.glPopMatrix();
        
        gl.glPushMatrix();
        gl.glRotatef(-angle, 0, 0, 1);
        gl.glTranslatef(2, 0, 0);
        gl.glScalef(mRed, mRed, mRed);
        mSquare.draw(gl);
        
        gl.glPopMatrix();
        gl.glPopMatrix();
        angle++;
    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL10.GL_PROJECTION);        
        gl.glLoadIdentity();
        
        GLU.gluPerspective(gl, 45.0f, (float)width / height, 1.0f, 30.0f);
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        gl.glShadeModel(GL10.GL_SMOOTH);
        gl.glClearDepthf(1.0f);
        gl.glEnable(GL10.GL_DEPTH_TEST);
        gl.glDepthFunc(GL10.GL_LEQUAL);
        gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);


    }

}
